<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>订单处理页面</title>
	<%@ include file="/view/common/tags.jsp"%>
	<script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
  <style>
  .panel-heading{margin-top:0}
  .panel h3{font-size:18px}
  .panel-body .col-xs-6{padding-top:0}
  .panel-body p{height:14px;}
  .fieldName{width: 120px; text-align: right; display: inline-block;}
  .divH{height:395px}
  </style>
</head>
<body>
    <section class="content">
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="home">
                    <div class="row">
                    <div class="col-md-12">
                        <div class="box">
                            <div class="box-body">
                                <div class="panel panel-default panel-body" style="padding-bottom:5px;">
                                    <form class="form-horizontal" action="" method="post" id="dataForm">
                                        <input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>" />
                                        <input type="hidden" id="token" name="token" value="" />
                                        <div class="searchMenu">
                                            <div class="col-xs-4">
                                                <input type="button" id="fhFinish" name="fhFinish" disabled="disabled" class="btn btn-primary btn-sm" onclick="fhFinishBtn()" value="发货完成"/>
                                            </div>
                                            <div class="col-xs-4" >
                                                <input type="button" id="bjts" name="bjts" disabled="disabled" class="btn btn-primary btn-sm" onclick="bjtsBtn()" value="标记特殊"/>
                                            </div>
                                            <div class="col-xs-4">
                                                <input type="button" id="refund" name="refund" disabled="disabled" class="btn btn-primary btn-sm" onclick="refundBtn()" value="退  款"/>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="panel panel-body">
                                    <div class="panel-body col-xs-6 divH">
                                      <h3 class="text-center panel-heading" style="background:#ececec;">订单信息</h3>
                                      <p><span class="fieldName">订单编号：</span><span id="orderNo"></span></p>
                                      <p><span class="fieldName">游戏区服：</span><span id="gameInfo"></span></p>
                                      <p><span class="fieldName">订单状态：</span><span id="orderState"></span></p>
                                      <p><span class="fieldName">交易类型：</span><span id="tradeName" style="color:red;"></span></p>
                                      <p><span class="fieldName">商品小类：</span><span id="goodsSmallName"></span></p>
                                      <p><span class="fieldName">购买数量：</span><span id="buyPieceNum"></span></p>
                                      <p><span class="fieldName">订单金额：</span><span id="orderSumFee"></span>元</p>
                                      <p><span class="fieldName">收货角色名：</span><span id="roleSh"></span></p>
                                      <p><span class="fieldName">交易方式：</span><span id="jyfsName"></span></p>
                                      <p><span class="fieldName">交易地点：</span><span id="jyAddress"></span></p>
                                      <p><span class="fieldName">用户账号：</span><span id="buyerAccount"></span></p>
                                      <p><span class="fieldName">联系电话：</span><span id="buyerPhone"></span></p>
                                      <p><span class="fieldName">常用QQ：</span><span id="buyerQq"></span></p>
                                      <p id="tsbjReasonDesP" style="display: none; color:red;"><span class="fieldName">异常原因：</span><span id="tsbjReasonDesSpan"></span></p>
                                    </div>
                                    <div class=" panel-body col-xs-6 divH">
                                      <h3 class="text-center panel-heading" style="background:#ececec">卖家信息</h3>
                                      <p><span class="fieldName">用户账号：</span><span id="sellerAccount"></span></p>
                                      <p><span class="fieldName">联系电话：</span><span id="sellerPhone"></span></p>
                                      <p><span class="fieldName">联系QQ：</span><span id="sellerQq"></span></p>
                                      <p id="accountNameP"><span class="fieldName">游戏帐号：</span><span id="accountName"></span></p>
                                      <p id="accountPasswdP"><span class="fieldName">游戏密码：</span><span id="accountPasswd"></span></p>
                                      <p id="roleNameP"><span class="fieldName">角色名称：</span><span id="roleName"></span></p>
                                      <p id="roleLevelP"><span class="fieldName">角色等级：</span><span id="roleLevel"></span></p>
                                      <p id="goodsLocationDesP"><span class="fieldName">物品存放处：</span><span id="goodsLocationDes"></span></p>
                                      <p><span class="fieldName">方便交易时间：</span><span id="fbjyBeginTime"></span> - <span id="fbjyEndTime"></span></p>
                                      <p id="goodsBaseItem1P"><span class="fieldName">链接地址：</span><a href="" id="goodsBaseItem1" target="_blank"></a></p>
                                    </div>
                                    <div class=" panel-body col-xs-6">
                                      <h3 class="text-center panel-heading" style="background:#ececec">订单日志</h3>
                                      <p><span class="fieldName">生成时间：</span><span id="timeOrderCreate"></span></p>
                                      <p><span class="fieldName">支付时间：</span><span id="timeOrderPay"></span></p>
                                      <p><span class="fieldName">处理时间：</span><span id="timeKfsl"></span></p>
                                      <p><span class="fieldName">处理人：</span><span id="kfslAccount"></span></p>
                                      <p id="timeFhFinishedP"><span class="fieldName">完成时间：</span><span id="timeFhFinished"></span></p>
                                      <p id="expectInAccountP"><span class="fieldName">预计到账时间：</span><span id="expectInAccount"></span></p>
                                      <p id="kfdjReasonDesP"><span class="fieldName">退款原因：</span><span id="kfdjReasonDes"></span></p>
                                      <p id="timeOrderEndP"><span class="fieldName">退款时间：</span><span id="timeOrderEnd"></span></p>
                                    </div>
                                    <div class=" panel-body col-xs-6">
                                      <h3 class="text-center panel-heading" style="background:#ececec">商品信息</h3>
                                      <p><span class="fieldName">标题：</span><span id="goodsName"></span></p>
                                      <p><span class="fieldName">价格：</span><span id="goodsPrice"></span>元</p>
                                      <p><span class="fieldName">数量：</span><span id="perPieceNum"></span></p>
                                      <p><span class="fieldName">发布件数：</span><span id="publishPieceNum"></span></p>
                                      <p><span class="fieldName">商品描述：</span><span id="goodsDes"></span></p>
                                      <p><span class="fieldName">发布时间：</span><span id="goodsPublishTime"></span></p>
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="profile">...</div>
          </div>
    </section>
    <div id="bjtsDiv" style="display: none;">
        <div class="panel panel-body" style="padding-top: 35px;">
        <form class="form-horizontal" action="" method="post" id="bjtsForm">
            <input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>" />
            <input type="hidden" id="token" name="token" value="<%=request.getParameter("token")%>" />
            <div class="form-group" style="line-height: 25px;">
                <label class="col-xs-3 text-right">责任方：</label>
                <div class="col-xs-9">
                    <input type="radio" name="tsbjZrf" value="10" onclick="getReasonDictList(this.value)"/>&nbsp;买家&nbsp;&nbsp;
                    <input type="radio" name="tsbjZrf" value="20" onclick="getReasonDictList(this.value)"/>&nbsp;卖家&nbsp;&nbsp;
                    <input type="radio" name="tsbjZrf" value="30" onclick="getReasonDictList(this.value)"/>&nbsp;第三方
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">标记原因：</label>
                <div class="col-xs-8">
                    <sk:select cssClass="form-control select" id="tsbjReasonId" name="tsbjReasonId" value="" >
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" id="tsbjReasonDes" name="tsbjReasonDes" value=""/>
                </div>
            </div>
        </form>
        </div>
    </div>
    <%@ include file="/view/common/footer.jsp"%>
</body>
<script>

// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if (msgg && msgg!=null && msgg!='null') { 
	  layer.msg(msgg);
}
var rowId = 0, token = "";
var tableIndex = 0; // 添加修改的弹出框的ID
var orderStateDictList = ""; // 订单状态
var staffId = parent.$("#staffId").val();

$(function(){
	rowId = $("#rowId").val();
	token = sessionStorage.getItem("token");
    $("#token").val(token);
    

    // 获取订单状态信息
    $.ajax({
        type: "post",
        url: "${tradeV1}/tradeState/orderStateDictList",
        dataType: "json",
        success: function(data){
            orderStateDictList = data;
        }
    });
    
    // 获取订单信息数据
    findData();
    
    // 行点击事件
    $("body").on("click","table>tbody>tr",function(){
        $(this).css("background","#e1ecf1").siblings().css("background","");
    });
})

// 获取订单信息数据
function findData(){

    $.ajax({
        type: "post",
        url: "${tradeV1}/tradeOrders/getOrderData",
        data: {"rowId" : rowId, "token" : token, "pageFlag" : "orderCl"},
        dataType: "json",
        success: function(data){
            $("#tsbjReasonDesP").hide(); // 默认隐藏 特殊标记原因
            $("#timeFhFinishedP").hide(); // 默认隐藏 发货完成时间
            $("#expectInAccountP").hide(); // 默认隐藏 预计到账时间
            $("#kfdjReasonDesP").hide(); // 默认隐藏 退款原因
            $("#timeOrderEndP").hide(); // 默认隐藏 退款时间
            $("#goodsBaseItem1P").hide(); // 默认隐藏 基本信息1

            $("#accountNameP").hide(); // 担保需要 隐藏游戏帐号
            $("#accountPasswdP").hide(); // 担保需要 隐藏游戏密码
            $("#roleNameP").hide(); // 担保需要 隐藏角色
            $("#roleLevelP").hide(); // 担保需要 隐藏角色等级
            $("#goodsLocationDesP").hide(); // 担保需要 隐藏物品存放处
            
            if(data.rowId <= 0){
                layer.msg("获取订单信息失败！");
                $(".searchMenu").html("");
                return;
            }
            if(staffId != data.kfslId){
                layer.msg("您无权限操作此订单！");
                $(".searchMenu").html("<h3 style='color:red;'>您无权限操作此订单！</h3>");
                return;
            }
            
            // 根据订单状态 控制按钮的展现
            if(data.orderState == 10){ <%-- 订单生成 --%>
                $("#fhFinish").attr("disabled", false); // 发货完成可操作
                $("#bjts").attr("disabled", false); // 标记特殊可操作
            }
            if(data.orderState == 20){ <%-- 异常中 --%>
                $("#fhFinish").attr("disabled", false);
                $("#bjts").attr("disabled", true);
                $("#refund").attr("disabled", false);
                $("#tsbjReasonDesP").show();
            }
            <%-- 退款中、已退款 --%>
            if(data.orderState == 30 || data.orderState == 50 || data.orderState == 60 || data.orderState == 70){
                $("#refund").attr("disabled", true);
                $("#kfdjReasonDesP").show(); // 显示 退款原因
                $("#timeOrderEndP").show(); // 显示 退款时间
            }
            <%-- 已完成 --%>
            if(data.orderState == 0){
            	$("#fhFinish").attr("disabled", true);
                $("#bjts").attr("disabled", true);
                $("#refund").attr("disabled", true);
            	$("#timeFhFinishedP").show(); // 显示 发货完成时间
                $("#expectInAccountP").show(); // 显示 预计到账时间
            }
            
            // 订单信息
            $("#orderNo").html(data.orderNo);
            $("#gameInfo").html(data.gameName + "/" + data.areaName + "/" + data.serverName);
            for(var i in orderStateDictList){
                if(orderStateDictList[i]["value"] == data.orderState){
                    $("#orderState").html(orderStateDictList[i]["label"]);
                }
            }
            $("#tradeName").html(data.tradeName);
            $("#goodsSmallName").html(data.goodsSmallName);
            $("#buyPieceNum").html(data.buyPieceNum);
            $("#orderSumFee").html(data.orderSumFee);
            $("#roleSh").html(data.roleSh);
            $("#jyfsName").html(data.jyfsName);
            $("#jyAddress").html(data.jyAddress);
            $("#buyerAccount").html(data.buyerAccount);
            $("#buyerPhone").html(data.buyerPhone);
            $("#buyerQq").html(data.buyerQq);
            var tsbjZrf = "买家原因";
            if(data.tsbjZrf == 20){
            	tsbjZrf = "卖家原因";
            } else if(data.tsbjZrf == 30){
            	tsbjZrf = "第三方原因";
            }
            $("#tsbjReasonDesSpan").html(tsbjZrf + "：" + data.tsbjReasonDes);
            
            // 卖家信息
            $("#sellerAccount").html(data.sellerAccount);
            $("#sellerPhone").html(data.sellerPhone);
            $("#sellerQq").html(data.sellerQq);
            $("#goodsBaseItem1").html(data.goodsBaseItem1);
            $("#goodsBaseItem1").attr("href", data.goodsBaseItem1);
            if (data.goodsBaseItem3.indexOf("10_")>-1 || data.goodsBaseItem3.indexOf("20_")>-1 || data.goodsBaseItem3.indexOf("30_")>-1) {
                $("#goodsBaseItem1P").show();
            }

            // 寄售需要展示卖家的游戏相关信息
            if(data.tradeId == 10){
	            $("#accountNameP").show(); 
	            $("#accountPasswdP").show();
	            $("#roleNameP").show();
	            $("#roleLevelP").show();
	            $("#goodsLocationDesP").show();
	            $("#accountName").html(data.accountName);
	            $("#accountPasswd").html(data.accountPasswd);
	            $("#roleName").html(data.roleName);
	            $("#roleLevel").html(data.roleLevel);
	            $("#goodsLocationDes").html(data.goodsLocationDes);
            }
            $("#fbjyBeginTime").html(data.fbjyBeginTime + ":00");
            $("#fbjyEndTime").html(data.fbjyEndTime + ":00");
            
            // 商品信息
            $("#goodsName").html(data.goodsName);
            $("#goodsPrice").html(data.goodsPrice);
            $("#perPieceNum").html(data.perPieceNum);
            $("#publishPieceNum").html(data.publishPieceNum);
            $("#goodsDes").html(data.goodsDes);
            $("#goodsPublishTime").html(data.goodsPublishTime);
            
            // 订单日志
            $("#timeOrderCreate").html(data.timeOrderCreate);
            $("#timeOrderPay").html(data.timeOrderPay);
            $("#timeKfsl").html(data.timeKfsl);
            $("#kfslAccount").html(data.kfslAccount);
            $("#timeFhFinished").html(data.timeFhFinished);
            $("#expectInAccount").html(data.expectInAccount);
            $("#kfdjReasonDes").html(data.tsbjReasonDes);
            $("#timeOrderEnd").html(data.timeOrderEnd);
        }
    });
}

// 发货完成
function fhFinishBtn(){
	layer.confirm("您确认发货吗？", {btn: ['确认', '取消']}, 
	        function(){
	          $.ajax({
	              url: "${tradeV1}/tradeOrders/orderClFhFinish",
	              type: "post",
	              cache: false,
	              data: {rowId:rowId, token: token},
	              dataType:"json",
	              async:false,
	              success: function(data) {
	                  if (data.code == 0) { 
	                      layer.msg("标记完成成功", {icon: 1});
	                      findData();
	                  } else if(data.code == "-2"){
	                      window.location.href="${sysManagerV1}/";
	                  } else {
	                      layer.msg(data.message, {icon: 5});
	                  }
	              }
	          });
	    });
}

// 标记特殊
function bjtsBtn(){
	var bjtsIndex = layer.open({
        type: 1,
        title: "标记特殊",
        closeBtn: 1,
        shadeClose: true,
        area: ['400px', '265px'],
        content: $("#bjtsDiv"),
        btn: ["确 认","关 闭"], 
        yes: function(index, layero){
        	
        	var tsbjZrf = $("input[name='tsbjZrf']:checked").val();
        	if(!CheckUtil.isNotNull(tsbjZrf)){
        		layer.msg("请选择责任方！");
        		return;
        	}
        	
        	var tsbjReasonId = $("#tsbjReasonId").find("option:selected").val();
        	if(!CheckUtil.isNotNull(tsbjReasonId)){
        		layer.msg("请选择异常原因！");
        		return;
        	}
        	$("#tsbjReasonDes").val($("#tsbjReasonId").find("option:selected").text());
        	
        	$.ajax({
                type: "post",
                url: "${tradeV1}/tradeOrders/orderClBjts",
                data: new FormData($("#bjtsForm")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data){
                    if(data.code == 0){
                    	layer.msg("标记特殊成功！");
                    } else if (data.code == -2) {
                        window.location.href = "${sysManagerV1}/";
                    } else{
                    	layer.msg(data.message);
                    }
                    layer.close(bjtsIndex);
                	findData();
                }
            });
        }
    });
}

// 退款
function refundBtn(){
	layer.confirm("您确认退款吗？", {btn: ['确认', '取消']}, 
	    function(){
          $.ajax({
              url: "${tradeV1}/tradeOrders/orderClRefund",
              type: "post",
              cache: false,
              data: {rowId:rowId, token: token},
              dataType:"json",
              async:false,
              success: function(data) {
                  if (data.code == 0) { 
                      layer.msg("退款成功", {icon: 1});
                      findData();
                  } else if(data.code == "-2"){
                      window.location.href="${sysManagerV1}/";
                  } else {
                      layer.msg(data.message, {icon: 5});
                  }
              }
          });
    });
}

// 获取原因
function getReasonDictList(tsbjZrf){
    $.ajax({
        type: "post",
        url: "${tradeV1}/tradeBaseReasons/reasonSelect",
        data: {"reasonTypeId" : 18, "tsbjZrf" : tsbjZrf, "token" : token},
        dataType: "json",
        success: function(data){
            if(data.length <= 0){
                return;
            }
            
            $("#tsbjReasonId").empty();
            var option = "<option value=''>请选择</option>"
            $("#tsbjReasonId").append(option);
            
            $.each(data, function (index, item) {
                option = "<option value='" + item.value + "'>" + item.label + "</option>"
                $("#tsbjReasonId").append(option);
            });
        }
    });
}

</script>
</html>